package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IDisputeDealView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *诉求服务办理
 */
public class AppealDealPest {

    private IDisputeDealView iDisputeDealView;

    public AppealDealPest(IDisputeDealView iDisputeDealView) {
        this.iDisputeDealView=iDisputeDealView;
    }


    /**
     * 办理/办结/回退
     * @param appealId 诉求事件id
     * @param stepRecordId 事件步骤id
     * @param content 处理意见/处理描述
     * @param operationCode 操作码:提交操作对应的数字到后台以进行对应操作,对应关系:(2030-回退,2050-办理,2070-办结)
     * @param files 附件路径信息
     */
    public void acceptAppeal(String appealId, String stepRecordId , String content , String operationCode,
                            List<String> files){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("appealId", appealId);
        map.put("stepRecordId",stepRecordId);
        map.put("content",content);
        map.put("operationCode",operationCode);
        if (files!=null&&files.size()>0){
            String str="";
            for (int i=0;i<files.size();i++){
                if(i==files.size()-1){
                    str=str+files.get(i);
                }else {
                    str=str+files.get(i)+",";
                }
            }
            map.put("filePaths",str);
        }
        new ApiManager().acceptAppeal(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                iDisputeDealView.showMes("事件处理成功");
            }
            @Override
            public void onFailures(String message) {
                iDisputeDealView.showError(message);
            }
        });
    }


    /**
     * 交办
     * @param appealId 诉求事件id
     * @param stepRecordId 事件步骤id
     * @param hostOrgId 主办单位组织机构id
     * @param chaoguOrgIds 抄告单位组织机构id(逗号分隔)
     * @param description 处理意见/处理描述
     * @param deadline 截止时间
     * @param operationCode 操作码:提交操作对应的数字到后台以进行对应操作,对应关系:(2010-交办)
     * @param files
     */
    public void acceptAppeal(String appealId, String stepRecordId , String hostOrgId,String chaoguOrgIds,
                           String description,String deadline,String operationCode,
                            List<String> files){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("appealId", appealId);
        map.put("stepRecordId",stepRecordId);
        map.put("shunt.hostOrgId",hostOrgId);
        map.put("shunt.chaoguOrgIds",chaoguOrgIds);
        map.put("shunt.description",description);
        map.put("shunt.deadline",deadline);
        map.put("operationCode",operationCode);
        if (files!=null&&files.size()>0){
            String str="";
            for (int i=0;i<files.size();i++){
                if(i==files.size()-1){
                    str=str+files.get(i);
                }else {
                    str=str+files.get(i)+",";
                }
            }
            map.put("filePaths",str);
        }
        new ApiManager().acceptAppeal(map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                iDisputeDealView.showMes("事件处理成功");
            }
            @Override
            public void onFailures(String message) {
                iDisputeDealView.showError(message);
            }
        });
    }

}
